Assignment 4

Before working on this assignment please read these instructions fully. In the submission area, you will notice that you can click the link to Preview the Grading for each step of the assignment. This is the criteria that will be used for peer grading. Please familiarize yourself with the criteria before beginning the assignment.

This assignment requires that you to find at least two datasets on the web which are related, and that you visualize these datasets to answer a question with the broad topic of economic activity or measures (see below) for the region of Ann Arbor, Michigan, United States, or United States more broadly.

You can merge these datasets with data from different regions if you like! For instance, you might want to compare Ann Arbor, Michigan, United States to Ann Arbor, USA. In that case at least one source file must be about Ann Arbor, Michigan, United States.

You are welcome to choose datasets at your discretion, but keep in mind they will be shared with your peers, so choose appropriate datasets. Sensitive, confidential, illicit, and proprietary materials are not good choices for datasets for this assignment. You are welcome to upload datasets of your own as well, and link to them using a third party repository such as github, bitbucket, pastebin, etc. Please be aware of the Coursera terms of service with respect to intellectual property.

Also, you are welcome to preserve data in its original language, but for the purposes of grading you should provide english translations. You are welcome to provide multiple visuals in different languages if you would like!

As this assignment is for the whole course, you must incorporate principles discussed in the first week, such as having as high data-ink ratio (Tufte) and aligning with Cairo’s principles of truth, beauty, function, and insight.

Here are the assignment instructions:

  • State the region and the domain category that your data sets are about (e.g., Ann Arbor, Michigan, United States and economic activity or measures).
  • You must state a question about the domain category and region that you identified as being interesting.
  • You must provide at least two links to available datasets. These could be links to files such as CSV or Excel files, or links to websites which might have data in tabular form, such as Wikipedia pages.
  • You must upload an image which addresses the research question you stated. In addition to addressing the question, this visual should follow Cairo's principles of truthfulness, functionality, beauty, and insightfulness.
  • You must contribute a short (1-2 paragraph) written justification of how your visualization addresses your stated research question.

What do we mean by economic activity or measures? For this category you might look at the inputs or outputs to the given economy, or major changes in the economy compared to other regions.

Tips

  • Wikipedia is an excellent source of data, and I strongly encourage you to explore it for new data sources.
  • Many governments run open data initiatives at the city, region, and country levels, and these are wonderful resources for localized data sources.
  • Several international agencies, such as the United Nations, the World Bank, the Global Open Data Index are other great places to look for data.
  • This assignment requires you to convert and clean datafiles. Check out the discussion forums for tips on how to do this from various sources, and share your successes with your fellow students!

Example

Looking for an example? Here's what our course assistant put together for the Ann Arbor, MI, USA area using sports and athletics as the topic. Example Solution File

Answers

Question 1.

State the region and the domain category that your data sets are about (e.g., Ann Arbor, Michigan, United States and economic activity or measures).</b>

Ann Arbor, Michigan, United States
Economic activity or measures

Question 2

You must state a question about the domain category and region that you identified as being interesting.</b>

How have the hourly earnings changed by sector over the last 10 years?

Question 3

You must provide at least two links to available datasets. These could be links to files such as CSV or Excel files, or links to websites which might have data in tabular form, such as Wikipedia pages.</b>


Professional and Business Services
Manufacturing, Trade,
Transportation, and Utilities, and
Education and Health Services


https://data.bls.gov/timeseries/LAUMT261146000000005&output_view=data&include_graphs=false (Local Area Unemployment Statistics ) https://data.bls.gov/timeseries/SMU26114606000000001&output_view=data&include_graphs=false (Professional and Business Services)
https://data.bls.gov/timeseries/SMU26114606500000001&output_view=data&include_graphs=false (Education and Health Services)
https://data.bls.gov/timeseries/SMU26114603000000001&output_view=data&include_graphs=false (Manufacturing)
https://data.bls.gov/timeseries/SMU26114604000000001&output_view=data&include_graphs=false (Trade, Transportation, and Utilities)

Question 4

You must upload an image which addresses the research question you stated. In addition to addressing the question, this visual should follow Cairo's principles of truthfulness, functionality, beauty, and insightfulness.</b>

Ann Arbor Salary AVG.png

Question 5

You must contribute a short (1-2 paragraph) written justification of how your visualization addresses your stated research question.</b>

This chart answers the research question by displaying the hourly earnings average among industry sectors in Ann Arbor, Metro Area, Michigan. The following sectors have been analyzed: Education & Health Services, Trade, Transportation and Utilities, Professional and Business Services, and Manufacturing. The data collected represents the period of ten years, between 2007 and 2017. The series used in this assignment have been gathered from the Bureau of Labor Statistics individually, and data cleaning and processing needed to be performed. Information from several industry sectors is available in a big range of formats for download.

The Professional and Business Services' sector showed the highest variation, especially after 2014. Trade and Education are very close to each other, mainly after 2010, when the Trade sector started to decline and the Education sector average rate started to increase. The Manufacturing sector was the one with the lowest average, declining from the beginning of the data series, and only increased from 2010. Employment data for the same region is also available on that site, which allowed us to correlate these values with each sector. Therefore, we came to a conclusion the sector Professional and Business Services presented strong correlation with employment rate (0.903), meaning the average earnings for this sector has a high tendency to increase as the employment increases.

A line chart has been chosen because it is better for historically disposed data. In order to incorporate Cairo's principles, we have applied some visual concepts to this chart. The labels were softened to avoid user distraction. Also, only the line with the highest average variation had a strong color; the remaining colors have been softened to provide a simple look and feel. Frames, ticks and graph background were removed. Finally, legends were placed appropriately to identify the lines easier.

Coding


In [1]:
#Imports
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib notebook

In [2]:
df_employment = pd.read_csv('Week_4_datasets/Unemployment Statistics.csv')
df_manufacturing = pd.read_csv('Week_4_datasets/Manufacturing.csv')
df_transportation = pd.read_csv('Week_4_datasets/Trade and Transportation.csv')
df_professional_services = pd.read_csv('Week_4_datasets/Professional and Business Services.csv')
df_education_and_health = pd.read_excel('Week_4_datasets/SeriesReport-20170327173049_eca63d.xlsx', skiprows=12)

In [4]:
df_education_and_health = df_education_and_health[['Series ID', 'Year', 'Period', 'Value']]

In [5]:
df_employment = df_employment[['Year', 'Period', 'employment']]

In [6]:
df_employment['education_health'] = df_education_and_health['Value']
df_employment['manufacturing'] = df_manufacturing['Value']
df_employment['trade_transportation'] = df_transportation['Value']
df_employment['professional_services'] = df_professional_services['Value']

In [7]:
df_employment.head()


Out[7]:
Year Period employment education_health manufacturing trade_transportation professional_services
0 2007 Jan 179354 23.7 20.1 27.1 26.8
1 2007 Feb 181109 23.9 19.8 26.8 27.3
2 2007 Mar 181938 24.1 19.7 26.7 27.4
3 2007 Apr 180396 24.2 19.3 26.7 27.6
4 2007 May 177706 24.2 19.2 27.1 27.8

In [8]:
df_employment_grouped = df_employment.set_index(['Year', 'Period'])

In [9]:
df_employment_grouped.head()


Out[9]:
employment education_health manufacturing trade_transportation professional_services
Year Period
2007 Jan 179354 23.7 20.1 27.1 26.8
Feb 181109 23.9 19.8 26.8 27.3
Mar 181938 24.1 19.7 26.7 27.4
Apr 180396 24.2 19.3 26.7 27.6
May 177706 24.2 19.2 27.1 27.8

In [97]:
df_employment[df_employment['Period'] == 'Jan']


Out[97]:
Year Period employment education_health manufacturing trade_transportation professional_services
0 2007 Jan 179354 23.7 20.1 27.1 26.8
12 2008 Jan 176916 24.1 18.3 27.0 26.2
24 2009 Jan 171037 24.0 13.4 26.1 24.3
36 2010 Jan 166736 24.1 13.8 24.8 24.7
48 2011 Jan 167702 24.4 13.8 25.2 25.0
60 2012 Jan 168533 25.9 14.0 24.6 24.5
72 2013 Jan 171564 26.1 14.0 24.8 25.4
84 2014 Jan 174463 25.9 13.9 24.5 25.8
96 2015 Jan 179527 26.3 14.3 25.2 27.8
108 2016 Jan 187258 26.8 14.5 25.6 28.5
120 2017 Jan 185871(P) 26.9 14.6 25.3 30.2

In [10]:
df_employment_grouped['employment'] = df_employment_grouped['employment'].apply(lambda x: x.replace('(P)', ''))

In [11]:
df_employment_grouped['employment'] = df_employment_grouped['employment'].convert_objects(convert_numeric=True)
df_employment_grouped['education_health'] = df_employment_grouped['education_health'].convert_objects(convert_numeric=True)
df_employment_grouped['manufacturing'] = df_employment_grouped['manufacturing'].convert_objects(convert_numeric=True)
df_employment_grouped['trade_transportation'] = df_employment_grouped['trade_transportation'].convert_objects(convert_numeric=True)
df_employment_grouped['professional_services'] = df_employment_grouped['professional_services'].convert_objects(convert_numeric=True)


/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:1: FutureWarning: convert_objects is deprecated.  Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.
  if __name__ == '__main__':
/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:2: FutureWarning: convert_objects is deprecated.  Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.
  from ipykernel import kernelapp as app
/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:3: FutureWarning: convert_objects is deprecated.  Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.
  app.launch_new_instance()
/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:4: FutureWarning: convert_objects is deprecated.  Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.
/opt/conda/lib/python3.5/site-packages/ipykernel/__main__.py:5: FutureWarning: convert_objects is deprecated.  Use the data-type specific converters pd.to_datetime, pd.to_timedelta and pd.to_numeric.

In [12]:
dates = df_employment[df_employment['Period'] == 'Jan']

In [13]:
df_employment_grouped.corr()


Out[13]:
employment education_health manufacturing trade_transportation professional_services
employment 1.000000 0.595611 0.267775 0.354737 0.903148
education_health 0.595611 1.000000 -0.417294 -0.284855 0.558006
manufacturing 0.267775 -0.417294 1.000000 0.748787 0.243073
trade_transportation 0.354737 -0.284855 0.748787 1.000000 0.317782
professional_services 0.903148 0.558006 0.243073 0.317782 1.000000

In [29]:
# professional services have a high tendency to increase as employment rate increases (highest correlation) => 0.903 correlation

In [28]:
plt.figure(figsize=(9,6));
sns.heatmap(df_employment_grouped.corr());
plt.tight_layout()


/opt/conda/lib/python3.5/site-packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family ['sans-serif'] not found. Falling back to DejaVu Sans
  (prop.get_family(), self.defaultFamily[fontext]))

In [15]:
sns.set_style('white')

In [45]:
plt.figure(figsize=(9,6))
df_employment_grouped['education_health'].plot(label='Education & Health Services',
                                            lw=4, alpha=0.4);
df_employment_grouped['trade_transportation'].plot(label='Trade, Transportation, and Utilities', c='orangered',
                                            lw=4, alpha=0.4);
df_employment_grouped['professional_services'].plot(label='Professional and Business Services', c='green',
                                            lw=4);
df_employment_grouped['manufacturing'].plot(label='Manufacturing', c='navy',
                                            lw=4, alpha=0.4);

plt.xticks(dates['Year'].index, dates['Year'], fontsize=10, alpha=0.7);
plt.xlabel('Period');
plt.ylabel('Average hourly earnings by sector', alpha=0.8);
plt.legend(loc='best');
plt.title('10 Years average hourly earnings by sector in Ann Arbor, MI');
plt.tick_params(top='off', bottom='off', left='off', right='off');

ax = plt.gca()
ax.spines['top'].set_visible(False);
ax.spines['bottom'].set_visible(False);
ax.spines['right'].set_visible(False);
ax.spines['left'].set_visible(False);



In [46]:
plt.figure(figsize=(9,6))
df_employment_grouped['employment'].plot(label='employment',
                                            lw=4, alpha=1);
plt.xticks(dates['Year'].index, dates['Year'], fontsize=10, alpha=0.7);
plt.xlabel('Period');
plt.ylabel('Thousands of people', alpha=0.8);
plt.legend(loc='best');
plt.title('10 Years employment Statistics in Ann Arbor, MI');
plt.tick_params(top='off', bottom='off', left='off', right='off');

ax = plt.gca()
ax.spines['top'].set_visible(False);
ax.spines['bottom'].set_visible(False);
ax.spines['right'].set_visible(False);
ax.spines['left'].set_visible(False);



In [ ]: